'use strict'
const path = require('path')
// Gzip压缩需要的内容
// const CompressionPlugin = require('compression-webpack-plugin')
const port = process.env.port || 8080 // dev port

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: '',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: false, // 关闭eslint
  // lintOnSave: process.env.NODE_ENV === 'development',
  productionSourceMap: true, // 配置sorceMap
  devServer: {
    host: '192.168.0.45',
    port: port,
    hot: true,
    open: true,
    overlay: {
      warnings: false,
      errors: true
    }
  },
  configureWebpack(config) {
    if (process.env.NODE_ENV !== 'development') {
      // 打包的时候开启gzip可以很大程度减少包的大小，非常适合于上线部署，需要nginx配合
      config.plugins
        .push
        // new CompressionPlugin({
        //   test: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i,
        //   threshold: 10240,
        //   deleteOriginalAssets: false,
        // }),
        ()
    }
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    return {
      resolve: {
        alias: {
          '@': resolve('src')
        }
      }
    }
  }
}
